package com.mcxx.modules.miniSalvation.order.service.read;

import com.mcxx.modules.base.utils.QueryParamUtil;
import com.mcxx.modules.miniSalvation.order.dao.read.InspectionOrderReadDao;
import com.mcxx.modules.miniSalvation.order.dto.InspectionOrderDTO;
import com.mcxx.modules.miniSalvation.order.entity.InspectionOrderEntity;
import com.mcxx.modules.miniSalvation.order.param.InspectionOrderParam;
import com.mcxx.util.CommonUtil;
import com.mcxx.util.Constant;
import com.mcxx.util.DateUtil;
import com.yinhai.ta404.core.restservice.requestbean.PageParam;
import com.yinhai.ta404.core.restservice.resultbean.Page;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@TaTransactional(readOnly = true)
public class InspectionOrderReadService {

    @Autowired
    private InspectionOrderReadDao inspectionOrderReadDao;


    public List<InspectionOrderEntity> listAll() {
    	return inspectionOrderReadDao.listAll();
    }



    public InspectionOrderEntity getById(String id) {
    	return inspectionOrderReadDao.getById(id);
    }


    public Page listNotInBatch(InspectionOrderParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);
        if (CommonUtil.invalidArgs(param.getSendMonth())) {
            param.setSendMonth(DateUtil.getMonthString());
        }


        List<InspectionOrderDTO> list;
        if (Constant.BusinessCode.LINSHI.equals(param.getBusinessType())) {

            inspectionOrderReadDao.beginPager(pageParam);
            list = inspectionOrderReadDao.listNotInBatch500(param);
        } else {

            inspectionOrderReadDao.beginPager(pageParam);
            list = inspectionOrderReadDao.listNotInBatch(param);
        }


        return inspectionOrderReadDao.endPager(list);
    }


    public Page listByCondition(InspectionOrderParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);


        List<InspectionOrderDTO> list;
        if (Constant.BusinessCode.LINSHI.equals(param.getBusinessType())) {

            inspectionOrderReadDao.beginPager(pageParam);
            list = inspectionOrderReadDao.listByCondition500(param);
        } else {

            inspectionOrderReadDao.beginPager(pageParam);
            list = inspectionOrderReadDao.listByCondition(param);
        }


        return inspectionOrderReadDao.endPager(list);
    }


    public int countByBatchId(String batchId) {
        return inspectionOrderReadDao.countByBatchId(batchId);
    }


    public Page listResultByCondition(InspectionOrderParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);


        List<InspectionOrderDTO> list;
        if (Constant.BusinessCode.LINSHI.equals(param.getBusinessType())) {

            inspectionOrderReadDao.beginPager(pageParam);
            list = inspectionOrderReadDao.listResultByCondition500(param);
        } else {

            inspectionOrderReadDao.beginPager(pageParam);
            list = inspectionOrderReadDao.listResultByCondition(param);
        }


        return inspectionOrderReadDao.endPager(list);
    }
}
